package pub.guoxin.oops.common.protocol.entity.map;

import lombok.Getter;
import lombok.Setter;

import java.util.HashMap;
import java.util.Objects;

/**
 * Created by guoxin on 18-3-8.
 */
@Getter
@Setter
public class DataProtocolMap<V> extends HashMap<Integer, V> {

    private static final long serialVersionUID = 4624985474330828728L;

    public static <V> DataProtocolMap<V> newDataProtocolMap(){
        return new DataProtocolMap<>();
    }

    public void register(Integer key, V value) {
        if (Objects.nonNull(get(key))) {
            throw new IllegalArgumentException("key(\"" + key + "\") value(\"" + value.toString() + "\") is exists");
        }
        put(key, value);
    }

}
